﻿@using Telerik.Web.Mvc.UI
@using MvcFront.Models

@{
    ViewBag.Title = "Index";
}
    @Html.ValidationSummary(true)
<h2>Формы документов</h2>

@Html.ActionLink("Добавить форму", "Create")
@(Html.Telerik().Grid<DocTemplateListViewModel>()
            .DataBinding(dataBinding => dataBinding.Ajax().Select("_DocTemplatesList", "DocTemplateList"))
            .Name("DocTemplateListGrid")
            .ClientEvents(events => events.OnComplete("onComplete"))
                   .Columns(columns =>
                   {
                       columns.AutoGenerate(column =>
                       {
                           column.Width = "150px";
                           if (column.Member == "DocTemplateId")
                               column.Visible = false;
                       });
                       columns.Command(command =>
                       {
                           command.Custom("viewDetails").Text("Информация")
                            .DataRouteValues(route => route.Add(o => o.DocTemplateId).RouteKey("id"))
                            .Action("Details", "DocTemplateList")
                            .HtmlAttributes(new { style = "text-align: center" });
                           command.Custom("EditDetails").Text("Редактировать")
                            .DataRouteValues(route => route.Add(o => o.DocTemplateId).RouteKey("id"))
                            .Action("Edit", "DocTemplateList")
                            .HtmlAttributes(new { style = "text-align: center" });
                           command.Custom("DocTemplateFieldsManagment").Text("Редактировать поля")
                            .DataRouteValues(route => route.Add(o => o.DocTemplateId).RouteKey("id"))
                            .Action("DocTemplateFieldsManagment", "DocTemplateList")
                            .HtmlAttributes(new { style = "text-align: center" });
                           command.Custom("ChangeStateDetails").Text("Выключить/Выключить")
                            .DataRouteValues(route => route.Add(o => o.DocTemplateId).RouteKey("id"))
                            .Ajax(true)
                            .Action("ChangeState", "DocTemplateList")
                            .HtmlAttributes(new { style = "text-align: center" });
                           command.Custom("DeleteDetails").Text("Удалить")
                            .DataRouteValues(route => route.Add(o => o.DocTemplateId).RouteKey("id"))
                            .Action("Delete", "DocTemplateList")
                            .HtmlAttributes(new { style = "text-align: center" });
                       }).Width(50);
                   })
                 .Sortable()
                .Pageable()

      ) 
      
<script type="text/javascript">
    function onComplete(e) {
        if (e.name == "ChangeStateDetails") {
            var grid = $('#DocTemplateListGrid').data("tGrid");
            if (grid != null) {
                grid.rebind();
            }
        }
    }
</script>